package yingke.com.yingke.factory;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import yingke.com.yingke.ui.left.attention.AttentionFragment;
import yingke.com.yingke.ui.left.hot.HotFragment;
import yingke.com.yingke.ui.left.nearby.NearbyFragment;

/**
 * Created by Administrator on 2016/10/19 0019.
 */

public class LeftFragmentFactory {
    private static final int ATTENTION = 0;//关注
    private static final int HOT = 1;//热门
    private static final int NEARBY = 2;//附近
    private static SparseArray<Fragment> fragments = new SparseArray<>();

    //利用该工具类创建主页面的两个个TabFragment
    public static Fragment createFragment(int index) {
        //从集合中获取
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case ATTENTION://关注
                    fragment = new AttentionFragment();
                    break;
                case HOT://热门
                    fragment = new HotFragment();
                    break;
                case NEARBY://附近
                    fragment = new NearbyFragment();
                    break;


            }
            //把创建好的fragment放入集合，方便下次使用
            fragments.put(index, fragment);
        }
        return fragment;

    }
}
